package com.rabbiter.em.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@Slf4j
public class PathUtils {
    public static String getClassLoadRootPath() {
        String path = "";
        try {
            String resourcePath = PathUtils.class.getClassLoader().getResource("").getPath();
            if (resourcePath.contains(".jar")) {
                path = new File(PathUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent();
            } else {
                path = URLDecoder.decode(resourcePath, "utf-8").replace("/target/classes", "");
            }
            log.info("=================PathUtils获取路径===========================path:{}", path);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return path;
    }

    public static void main(String[] args) {
        System.out.println(getClassLoadRootPath());
    }
}
